<template>
  <div class="login" >
    <div class="login-wrap">
      <el-row type="flex" justify="center">
        <el-form ref="loginForm" :model="admin" :rules="rules" @keyup.enter.native="handleEnterKey" status-icon label-width="80px">
          <h3>恒利管理系统</h3>
          <hr>
          <el-form-item prop="username" label="用户名">
            <el-input v-model="admin.username" placeholder="请输入用户名" prefix-icon></el-input>
          </el-form-item>
          <el-form-item id="password" prop="password" label="密码">
            <el-input v-model="admin.password" show-password  placeholder="请输入密码"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-upload"  @click="login()">登 录</el-button>
          </el-form-item>
        </el-form>
      </el-row>
    </div>
  </div>
</template>

<script>
import request from "@/utils/request";

	export default {

		data() {
			return {
				admin: {
          username:"",
          password:""
        }
			}
		},
		methods: {
      async handleEnterKey(event) {
        if (event.key === 'Enter') {
            this.login(); // 验证通过，执行登录操作
        }
      },
			login() {
        // 拦截器此时把res.data变成res了
				request.post("/admin/employee/login",this.admin).then(res=>{
					if(res.code=='1'){
						this.$message({
							message:'登录成功',
							type:'success'
						});
            // 直接本地存储
            localStorage.setItem("user",JSON.stringify(res))
						this.$router.push("/");
					}else{
						this.$message({
							message: res.msg,
							type:'error'
						});
					}
				})
			}
		}
	}
</script>


<style scoped>

.login {
  width: 100%;
  height: 100vh;
  background: url("@/assets/pexels-tyler-lastovich-772803.jpg") no-repeat;
  background-size: cover;
  overflow: hidden;
}
.login-wrap {
  background: url("@/assets/pexels-henry-&-co-1939485.jpg") no-repeat;
  background-size: cover;
  width: 400px;
  height: 300px;
  margin: 400px auto;
  overflow: hidden;
  padding-top: 10px;
  line-height: 40px;
  border-radius: 10px;
  box-shadow: #2a2929 0px 0px 10px;
}
#password {
  margin-bottom: 5px;
}
h3 {
  color: #0babeab8;
  font-size: 24px;
  text-align: center;
}
hr {
  background-color: #444;
  margin: 20px auto;
}
a {
  text-decoration: none;
  color: #aaa;
  font-size: 15px;
}
a:hover {
  color: coral;
}
.el-button {
  width: 80%;
  margin-top: 20px;
}
</style>